<?php
use app\models\ContentCategory;
use app\models\Content;

/*SEO信息*/
function smarty_block_seo($params, $content, Smarty_Internal_Template $template, &$repeat)
{
	// $repeat = false;
    $app_id = Yii::$app->params['app_id'];
    // p($_GET['category']);
    $title = '';
    $keyword = '';
    $describe = '';
    if(isset($_GET['id'])){
        $seo = Content::find()
                    ->select(['title', 'keyword', 'describe'])
                    ->where("app_id = :app_id and content_id = :id and display = 2 and state = 3", [':app_id' => $app_id, ':id' => $_GET['id']])->one();
        $title = $seo->title;
        $keyword = $seo->keyword;
        $describe = $seo->describe;
    }else{
        if(isset($_GET['category'])){
            $seo = ContentCategory::find()
                        ->select(['name', 'seo_title', 'seo_keyword', 'seo_describe'])
                        ->where("app_id = :app_id and alias = :alias and display = 2", [':app_id' => $app_id, ':alias' => $_GET['category']])->one();
            $title = $seo->seo_title?$seo->seo_title:$seo->name;
            $keyword = $seo->seo_keyword;
            $describe = $seo->seo_describe;
        }
    }
    // P($seo);

    
    $template->assign("title", $title);
    $template->assign("keyword", $keyword);
    $template->assign("describe", $describe);
    return $content;

}